Skip to content

refactor: formalize C ABI codec registry via as_c_name/from_c_name#265

Merged
streamer45 merged 7 commits intomainfrom
devin/1775564869-c-abi-codec-extensibility
Apr 7, 2026
Merged

refactor: formalize C ABI codec registry via as_c_name/from_c_name#265
streamer45 merged 7 commits intomainfrom
devin/1775564869-c-abi-codec-extensibility

Conversation

@staging-devin-ai-integration
Copy link
Copy Markdown
Contributor

@staging-devin-ai-integration staging-devin-ai-integration bot commented Apr 7, 2026

Summary

Centralizes C ABI codec name handling into a single source of truth (as_c_name()/from_c_name() on AudioCodec/VideoCodec), fixes EncodedVideo to carry codec metadata through the C ABI (was a TODO mapping to Binary), and eliminates duplicated codec-name logic across macros and conversions.

Key changes:

  • AudioCodec::as_c_name()/from_c_name() and VideoCodec equivalents in crates/core/src/types.rs — single source of truth for codec ↔ C name mapping
  • from_c_name is strict: canonical lowercase only (no serde aliases like "avc"/"avc1")
  • EncodedVideo now carries codec info via custom_type_id in packet_type_from_c/packet_type_to_c (was falling back to Binary)
  • CPacketTypeOwned::CodecName(CString) eliminates duplicated byte literals in packet_type_to_c
  • codec_name_to_cstring() made pub and used by all 8 macro sites in lib.rs — fully centralizes CString construction with expect() (fail-fast on programmer errors)
  • tracing::warn! on both EncodedVideo and EncodedAudio null custom_type_id fallbacks (aids debugging vs backward compat)
  • Doc comments on field loss through C ABI (bitstream_format, codec_private, etc.) and corrected EncodedAudio doc (audio_codeccustom_type_id)
  • 7 new roundtrip tests + strict-mode rejection test

Adding a new codec now requires changes in exactly 2 methods (as_c_name + from_c_name) instead of 6+ locations.

Review & Testing Checklist for Human

  • Verify from_c_name strict mode is acceptable — "avc"/"avc1" no longer accepted in C ABI (serde aliases still work for config deserialization)
  • Verify EncodedVideo backward compat: null custom_type_idBinary fallback with tracing::warn! is appropriate for pre-codec-string plugins
  • Spot-check macro sites in lib.rs to confirm codec_name_to_cstring calls look correct (4 macro blocks × 2 codec arms each)
  • Consider whether codec_name_to_cstring should remain pub or if there's a way to scope it more narrowly (needed pub because macros expand in plugin crates)

Notes

  • The OpusAudio discriminant is preserved for backward compat with v1-v7 plugins
  • CPacketTypeInfo struct layout is unchanged — custom_type_id field already existed, we're reusing it for EncodedVideo
  • No existing plugins use EncodedVideo, so no plugin-side breakage
  • Future consideration: proc macro or strum derive for from_c_name to get compile-time enforcement of the inverse mapping (noted in review, deferred)

Link to Devin session: https://staging.itsdev.in/sessions/aff5f53f0854449fb15f91a1eef99f93
Requested by: @streamer45


Staging: Open in Devin

Centralizes codec name ↔ enum conversion in AudioCodec and VideoCodec,
eliminating hardcoded string matching duplicated across 6 locations in the
plugin SDK (conversions.rs, processor macro, source macro × input/output).

Key changes:
- Add AudioCodec::as_c_name()/from_c_name() and VideoCodec equivalents
  as the single source of truth for C ABI codec name strings.
- Fix EncodedVideo to carry codec info via custom_type_id (same pattern
  as EncodedAudio). Previously mapped to PacketType::Binary with a TODO.
  Null custom_type_id falls back to Binary for backward compat.
- Replace 4 duplicated match blocks in native_plugin_entry! and
  native_source_plugin_entry! macros with as_c_name() calls.
- Add EncodedVideo custom_type_id handling to both macros.
- Document the codec extensibility pattern in CPacketTypeInfo.
- Add roundtrip tests for all codec name conversions and C ABI encoding.

Adding a new codec now requires only two changes:
1. Add the variant to AudioCodec/VideoCodec
2. Add its name in as_c_name() and from_c_name()

No API version bump needed — CPacketTypeInfo struct layout unchanged.

BREAKING CHANGE: EncodedVideo pin declarations now carry codec info
via custom_type_id instead of mapping to Binary.

Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
@staging-devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

staging-devin-ai-integration[bot]

This comment was marked as resolved.

streamkit-devin and others added 6 commits April 7, 2026 12:53
…ec strings

Add CodecName(CString) variant to CPacketTypeOwned and a
codec_name_to_cstring() helper so packet_type_to_c derives its
null-terminated codec names from as_c_name() instead of maintaining
parallel hardcoded byte literals.

This makes the doc comment claim true: as_c_name()/from_c_name() are
now genuinely the only places codec-name strings live.

Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
- codec_name_to_cstring: use expect() instead of unwrap_or_default()
  to fail fast on programmer errors (matches lib.rs macro pattern)
- Add tracing::warn! when EncodedVideo null custom_type_id falls back
  to Binary (aids debugging of new plugins vs backward compat)
- Simplify map_err to forward original from_c_name() error messages
- Add doc comments clarifying intentional field loss (bitstream_format,
  codec_private, profile, level) through C ABI pin-type declarations

Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
- codec_name_to_cstring: use expect() instead of unwrap_or_default()
  to fail fast on programmer errors (matches lib.rs macro pattern)
- Add tracing::warn! when EncodedVideo null custom_type_id falls back
  to Binary (aids debugging of new plugins vs backward compat)
- Simplify map_err to forward original from_c_name() error messages
- Add doc comments clarifying intentional field loss (bitstream_format,
  codec_private, profile, level) through C ABI pin-type declarations

Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
- Make from_c_name strict (canonical lowercase only): remove 'avc'/'avc1'
  aliases from VideoCodec::from_c_name — serde aliases are for config
  deserialization, C ABI is a controlled interface with canonical names
- Add tracing::warn! for EncodedAudio null custom_type_id fallback to
  Opus (matching the EncodedVideo pattern)
- Make codec_name_to_cstring pub and replace 8 inline CString::new()
  .expect() sites in lib.rs macros — fully centralizes CString
  construction for codec names
- Fix EncodedAudio doc comment: audio_codec -> custom_type_id
- Replace alias roundtrip test with strict-mode rejection test

Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
@streamer45 streamer45 merged commit 87e3828 into main Apr 7, 2026
17 checks passed
@streamer45 streamer45 deleted the devin/1775564869-c-abi-codec-extensibility branch April 7, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants